package com.hycreate.platform.modules.dismissthecase;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hycreate.platform.common.config.Global;
import com.hycreate.platform.common.persistence.Page;
import com.hycreate.platform.common.utils.StringUtils;
import com.hycreate.platform.common.web.BaseController;

/**
 * 结案驳回Controller
 * @author wang
 * @version 2017-11-29
 */
@Controller
@RequestMapping(value = "${adminPath}/dismissthecase/yhcgDismissthecase")
public class YhcgDismissthecaseController extends BaseController {

	@Autowired
	private YhcgDismissthecaseService yhcgDismissthecaseService;
	
	@ModelAttribute
	public YhcgDismissthecase get(@RequestParam(required=false) String id) {
		YhcgDismissthecase entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = yhcgDismissthecaseService.get(id);
		}
		if (entity == null){
			entity = new YhcgDismissthecase();
		}
		return entity;
	}
	
	@RequestMapping(value = "listjie",method=RequestMethod.POST)
	@ResponseBody
	public List<YhcgDismissthecase> listjie(YhcgDismissthecase yhcgDismissthecase, HttpServletRequest request, HttpServletResponse response, Model model) {
		yhcgDismissthecase.setStatus("1");
		List<YhcgDismissthecase> page = yhcgDismissthecaseService.findAllList(yhcgDismissthecase);
		return page;
	}

	@RequestMapping(value = "listbo",method=RequestMethod.POST)
	@ResponseBody
	public List<YhcgDismissthecase> listno(YhcgDismissthecase yhcgDismissthecase, HttpServletRequest request, HttpServletResponse response, Model model) {
		yhcgDismissthecase.setStatus("2");
		List<YhcgDismissthecase> page = yhcgDismissthecaseService.findAllList(yhcgDismissthecase);
		return page;
	}
	@RequiresPermissions("dismissthecase:yhcgDismissthecase:view")
	@RequestMapping(value = {"list", ""})
	public String list(YhcgDismissthecase yhcgDismissthecase, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<YhcgDismissthecase> page = yhcgDismissthecaseService.findPage(new Page<YhcgDismissthecase>(request, response), yhcgDismissthecase); 
		model.addAttribute("page", page);
		return "modules/dismissthecase/yhcgDismissthecaseList";
	}
	@RequiresPermissions("dismissthecase:yhcgDismissthecase:view")
	@RequestMapping(value = "form")
	public String form(YhcgDismissthecase yhcgDismissthecase, Model model) {
		model.addAttribute("yhcgDismissthecase", yhcgDismissthecase);
		return "modules/dismissthecase/yhcgDismissthecaseForm";
	}

	@RequiresPermissions("dismissthecase:yhcgDismissthecase:edit")
	@RequestMapping(value = "save")
	public String save(YhcgDismissthecase yhcgDismissthecase, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, yhcgDismissthecase)){
			return form(yhcgDismissthecase, model);
		}
		yhcgDismissthecaseService.save(yhcgDismissthecase);
		addMessage(redirectAttributes, "保存结案驳回成功");
		return "redirect:"+Global.getAdminPath()+"/dismissthecase/yhcgDismissthecase/?repage";
	}
	
	@RequiresPermissions("dismissthecase:yhcgDismissthecase:edit")
	@RequestMapping(value = "delete")
	public String delete(YhcgDismissthecase yhcgDismissthecase, RedirectAttributes redirectAttributes) {
		yhcgDismissthecaseService.delete(yhcgDismissthecase);
		addMessage(redirectAttributes, "删除结案驳回成功");
		return "redirect:"+Global.getAdminPath()+"/dismissthecase/yhcgDismissthecase/?repage";
	}

}